package co.edu.unal.geditor.view.tools;

import java.awt.Color;
import java.awt.Point;

import javax.swing.JOptionPane;

import co.edu.unal.geditor.controller.action.tool.ArcToolAction;
import co.edu.unal.geditor.model.ArcElement;
import co.edu.unal.geditor.model.GraphElement;


public class ArcCreationTool extends CreationTool
{
	// v0.6 : EllipseCreationTool provides its own Factory class 
	private static class Factory extends ToolFactory
	{
		protected Tool create()
		{
			return new ArcCreationTool();
		}
	}

	// this block executed when the class object is loaded in the VM
	// registers its Factory
	static
	{
		ToolFactory.register( ArcCreationTool.class.getName(), new Factory() );
	}


	@Override
	public GraphElement createObject(Point ptPressed, Point ptReleased) {
		ArcElement arc = null;
		int number;
		String sAngle = JOptionPane.showInputDialog("Arc meassure 0-360");
		if ( sAngle != "" ) {

			if( validate( sAngle ) ){
			number = Integer.parseInt( sAngle );
			arc = new ArcElement(ptPressed, ptReleased, ArcElement.getDefaultLinesColor(), number);
			}
			else{
			JOptionPane.showMessageDialog(null, "Input MUST be numeric");
			}
		}
		
		return arc;
	}
	private boolean validate( String value ) {
		try{
		Integer.parseInt( value );
		return true;
		} catch( NumberFormatException e ) {
		return false;
		} 
		}
	@Override
	protected void initAction()
	{
		setAction( new ArcToolAction() );
		if(feedbackGraphElemet==null)
			{
			feedbackGraphElemet = new ArcElement(new Point(0,0), new Point(20,20), Color.BLACK, 0);
			}
	}
}